import request from "@/utils/request";
import { ApiReturn } from "@/utils/request";

export interface Major {
  collageName?: string
  collageNum?: string
  createTime?: string
  majorName?: string
  majorNum?: string
  updateTime?: string
  showInput?: boolean
  majorClass?: number
  majorClassValue?: string
}

export interface Collage {
  collageName?: string
  collageNum?: string
  createTime?: string
  showInput?: boolean
  updateTime?: string
}

export interface Clazz {
  className?: string
  classNum?: string
  collageName?: string
  collageNum?: string
  createTime?: string
  majorName?: string
  majorNum?: string
  updateTime?: string
  showInput?: boolean
}

export interface ListResp<T> {
  data: T[]
  total: number
}

export class OtherService {
  static async getMajors(params: any): ApiReturn<ListResp<Major>> {
    return request.get('/majorInfos', { params });
  }

  static async getCollages(): ApiReturn<Collage[]> {
    return request.get('/collageinfos');
  }

  static async saveCollages(data: any, type: string): ApiReturn<any> {
    if (type == "add") {
      return request.post("/collageinfo", data)
    } else {
      const item: Collage = { collageName: data.collageName };
      return request.put(`/collageinfos/${data.collageNum}`, item)
    }
  }

  static async deleteCollage(collageNums: string[]): ApiReturn<any> {
    return request.delete("/collageinfos", { data: collageNums })
  }

  static async saveMajor(data: Major, type: string): ApiReturn<any> {
    if (type == "add") {
      return request.post("/majorInfos", data)
    } else {
      return request.put(`/majorInfos/${data.majorNum}`, data)
    }
  }

  static async deleteMajor(majorNums: string[]): ApiReturn<any> {
    return request.delete("/majorInfos", { data: majorNums })
  }

  static async listClass(params: any): ApiReturn<ListResp<Clazz>> {
    return request.get('/classes', { params });
  }

  static async saveClazz(data: Clazz, type: string): ApiReturn<any> {
    if (type == "add") {
      return request.post("/classes", data)
    } else {
      return request.put(`/classes/${data.classNum}`, data)
    }
  }

  static async deleteClazz(clazzNums: string[]): ApiReturn<any> {
    return request.delete("/classes", { data: clazzNums })
  }
}